<?php

/**
 * Class ModuleGroupLogic
 */
class ModuleGroupLogic extends Model
{
    private $_customerId = null;
    private $_modelModuleGroup = null;

    public function __construct()
    {
        $this->_customerId = Session::$user['customerId'];
        Session::switchCustomer(0);

        $this->_modelModuleGroup = D('ModuleGroup');

        Session::switchCustomer($this->_customerId);
    }

    /** --------------------------------------  增  -------------------------------------- */
    /** --------------------------------------  删  -------------------------------------- */
    /** --------------------------------------  改  -------------------------------------- */



    /** --------------------------------------  查  -------------------------------------- */

    /**
     * 查询模块列表, 需指定查询字段和查询条件
     *
     * @param string $fields
     * @param array  $where
     * @param string $order
     * @param string $orderBy
     * @param int    $start
     * @param int    $limit
     * @return mixed
     */
    public function selectPage($fields = '', array $where, $order = 'id', $orderBy = 'desc', $start = 0, $limit = 10)
    {
        return $this->_modelModuleGroup
            ->where($where)
            ->field($fields)
            ->order("$order $orderBy")
            ->limit($start, $limit)
            ->select();
    }

    /**
     * 查询模块列表总个数, 需指定查询条件
     *
     * @param array  $where
     * @return mixed
     */
    public function selectPageCount(array $where)
    {
        return $this->_modelModuleGroup
            ->where($where)
            ->field('id')
            ->count();
    }

    /**
     * 指定条件查询某个字段
     *
     * @param       $field
     * @param array $where
     * @return mixed
     */
    public function getFieldWithWhere($field, array $where)
    {
        return $this->_modelModuleGroup->where($where)->getField($field);
    }

    /**
     * 指定条件查询某个字段并且进行分组
     *
     * @param       $field
     * @param array $where
     * @return mixed
     */
    public function getFieldWithWhereDistinct($field, array $where)
    {
        return $this->_modelModuleGroup->where($where)->distinct(TRUE)->field($field)->select();
    }
}